home *** CD-ROM | disk | FTP | other *** search
/ ...taking it to the Macs! / ...taking it to the Macs!.iso / Extras / ActiveX Mac SDK / ActiveX SDK / Containers / ActiveXApp / CActiveXApp.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-17  |  4.7 KB  |  186 lines  |  [TEXT/CWIE]

  1. // =================================================================================
  2. //    CActiveXApp.cpp                    ©1996 Microsoft Corporation. All rights reserved.
  3. //                                    portions ©1995 Metrowerks Inc. All rights reserved.
  4. // =================================================================================
  5.  
  6. #include <LGrowZone.h>
  7. #include <LMenu.h>
  8. #include <LMenuBar.h>
  9. #include <LString.h>
  10. #include <LWindow.h>
  11. #include <PP_Messages.h>
  12. #include <PPobClasses.h>
  13. #include <UDesktop.h>
  14. #include <UDrawingState.h>
  15. #include <UMemoryMgr.h>
  16. #include <UReanimator.h>
  17. #include <URegistrar.h>
  18. #include <UTextTraits.h>
  19.  
  20. #include "ActiveXAppConstants.h"
  21. #include "CActiveXDocument.h"
  22. #include "CActiveXView.h"
  23. #include "urlapi.h"
  24.  
  25. #ifdef MULTI_CONTEXT_TEST_APP
  26. #include "CActiveXShadowView.h"
  27. #endif    //    MULTI_CONTEXT_TEST_APP
  28.  
  29. #include "CActiveXApp.h"
  30.  
  31. #include <compobj.h>
  32.  
  33. CActiveXApp *CActiveXApp::sDefaultApplication = NULL;
  34.  
  35. // =================================================================================
  36. //        • Main Program
  37. // =================================================================================
  38.  
  39. void
  40. main( void )
  41. {
  42.     // Initialize the heap. Parameter is number
  43.     // of master handle blocks to allocate.
  44.     InitializeHeap( 4 );
  45.     
  46.     // Initialize the MacOS toolbox.
  47.     UQDGlobals::InitializeToolbox( &qd );
  48.  
  49.     // Install a GrowZone function to catch  low memory situations.
  50.     // Parameter is the size of the memory reserve in bytes.
  51.     new LGrowZone( 20000 );
  52.  
  53.     // Create the application object and run it.
  54.     CActiveXApp    theApp;
  55.  
  56.     theApp.Run();
  57. }
  58.  
  59.  
  60. // ---------------------------------------------------------------------------------
  61. //        • CActiveXApp
  62. // ---------------------------------------------------------------------------------
  63.  
  64. CActiveXApp::CActiveXApp()
  65. {
  66.     // Setup the throw and signal actions.
  67.     SetDebugThrow_( debugAction_Alert );
  68.     SetDebugSignal_( debugAction_Alert );
  69.  
  70.     // Give global access to the application object
  71.     sDefaultApplication = this;
  72.  
  73.     // Register PowerPlant class creator functions.
  74.     RegisterAllPPClasses();
  75.  
  76.     // Register custom classes.
  77.     URegistrar::RegisterClass( CActiveXView::class_ID, (ClassCreatorFunc) CActiveXView::CreateActiveXViewStream );
  78. #ifdef MULTI_CONTEXT_TEST_APP
  79.     URegistrar::RegisterClass( CActiveXShadowView::class_ID, (ClassCreatorFunc) CActiveXShadowView::CreateActiveXShadowViewStream );
  80. #endif    //    MULTI_CONTEXT_TEST_APP
  81.     OpenUrlMoniker(NULL);
  82. }
  83.  
  84.  
  85. // ---------------------------------------------------------------------------------
  86. //        • ~CActiveXApp
  87. // ---------------------------------------------------------------------------------
  88.  
  89. CActiveXApp::~CActiveXApp()
  90. {
  91.     CloseUrlMoniker();
  92. }
  93.  
  94.  
  95. // ---------------------------------------------------------------------------------
  96. //        • StartUp
  97. // ---------------------------------------------------------------------------------
  98.  
  99. void
  100. CActiveXApp::StartUp()
  101. {
  102.     ObeyCommand( cmd_New, nil );
  103. }
  104.  
  105.  
  106. // ---------------------------------------------------------------------------------
  107. //        • FindCommandStatus
  108. // ---------------------------------------------------------------------------------
  109.  
  110. void
  111. CActiveXApp::FindCommandStatus(
  112.     CommandT    inCommand,
  113.     Boolean        &outEnabled,
  114.     Boolean        &outUsesMark,
  115.     Char16        &outMark,
  116.     Str255        outName )
  117. {
  118.     switch ( inCommand ) {
  119.     
  120.         case cmd_PageSetup:
  121.         {
  122.             // Short circuit the page setup command
  123.             // since this example doesn't print.
  124.             outEnabled = false;
  125.         }
  126.         break;
  127.  
  128.         default:
  129.         {
  130.             // Call inherited.
  131.             LDocApplication::FindCommandStatus( inCommand,
  132.                 outEnabled, outUsesMark, outMark, outName );
  133.         }
  134.         break;
  135.  
  136.     }
  137. }
  138.  
  139.  
  140. // ---------------------------------------------------------------------------------
  141. //        • OpenDocument
  142. // ---------------------------------------------------------------------------------
  143.  
  144. void
  145. CActiveXApp::OpenDocument(
  146.     FSSpec    *inMacFSSpec )
  147. {
  148.     // Create a new document using the file spec.
  149.     new CActiveXDocument( this, inMacFSSpec );
  150. }
  151.  
  152.  
  153. // ---------------------------------------------------------------------------------
  154. //        • MakeNewDocument
  155. // ---------------------------------------------------------------------------------
  156.  
  157. LModelObject *
  158. CActiveXApp::MakeNewDocument()
  159. {
  160.     // Make a new empty document.
  161.     return new CActiveXDocument( this, nil );
  162. }
  163.  
  164.  
  165. // ---------------------------------------------------------------------------------
  166. //        • ChooseDocument
  167. // ---------------------------------------------------------------------------------
  168.  
  169. void
  170. CActiveXApp::ChooseDocument()
  171. {
  172.     // Deactivate the desktop.
  173.     ::UDesktop::Deactivate();
  174.  
  175.     // Browse for a document.
  176.     SFTypeList            theTypeList = {'TEXT'};
  177.     StandardFileReply    theReply;
  178.     ::StandardGetFile( nil, 1, theTypeList, &theReply );
  179.  
  180.     // Activate the desktop.
  181.     ::UDesktop::Activate();
  182.     
  183.     // Send an apple event to open the file.    
  184.     if ( theReply.sfGood ) SendAEOpenDoc( theReply.sfFile );
  185. }
  186.